﻿var SelectedContentName = "";

function OpenContentEdit(ContentName) {

    var url = "/JotCMS/JotEditContent.aspx?c=" + ContentName;
    var features = "dialogWidth:735px;center:yes";
    var win = window.showModalDialog(url, "JotContentEdit", features);
}

function SaveContentToServer() {

    var _contentName = $("#ContentName").val();
    var _htmlContent = $('#txtDefaultHtmlArea').htmlarea('toHtmlString');
    var action = "Save";

    var dataToSend = { Content_Name: _contentName, HTMLContent: _htmlContent, Action: action };

    $.ajax({
        url: "/JotCMS/ContentAction.ashx",
        type: 'POST',
        data: dataToSend,
        success: function (data) {
            window.close();
            if (window.opener && !window.opener.closed) {
                window.opener.location.reload();
            }
        }
    });
}

function ClearCache(all) {

    var _contentName = $("#ContentName").val();
    var _htmlContent = $('#txtDefaultHtmlArea').htmlarea('toHtmlString');
    var action = (all == null ? "ResetItemCache" : "ResetAllCache");

    var dataToSend = { Content_Name: _contentName, HTMLContent: _htmlContent, Action: action };

    $.ajax({
        url: "/JotCMS/ContentAction.ashx",
        type: 'POST',
        data: dataToSend,
        success: function (data) {
            window.close();
            if (window.opener && !window.opener.closed) {
                window.opener.location.reload();
            }
        }
    });
}

function GoIntoEditMode(editMode) {

    if(editMode)
        window.location.href = window.location.href.replace("?JotEdit=1", "");
    else
        window.location.href = window.location.href + "?JotEdit=1";
}